package br.com.unb.provenance.entities;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.unb.provenance.domain.TypeInstitution;

@Entity
@Table(name = "Project")
public class Project extends Provenance {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Integer id;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "description")
	private String description;
	
	@Column(name = "coordinator")
	private String coordinator;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "project")
	private List<Institution> institutions;
	
	@Column(name = "start_date")
	@Temporal(TemporalType.DATE)
	private Date startDate;
	
	@Column(name = "end_date")
	@Temporal(TemporalType.DATE)
	private Date endDate;
	
	@Column(name = "notes")
	private String notes;
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "id_configuration")
	private Configuration configuration;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}	
	
	public List<Institution> getParticipatingInstitutions(){
		List<Institution> p = new ArrayList<>();
		for (Institution institution : institutions) {
			if(institution.getType().equals(TypeInstitution.PARTICIPATING)){
				p.add(institution);
			}
		}
		return p;
	}
	
	public List<Institution> getFundingInstitutions(){
		List<Institution> f = new ArrayList<>();
		for (Institution institution : institutions) {
			if(institution.getType().equals(TypeInstitution.FUNDING)){
				f.add(institution);
			}
		}
		return f;
	}

	public List<Institution> getInstitutions() {
		return institutions;
	}

	public void setInstitutions(List<Institution> institutions) {
		this.institutions = institutions;
	}

	public String getCoordinator() {
		return coordinator;
	}

	public void setCoordinator(String coordinator) {
		this.coordinator = coordinator;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}
	
	
}
